<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html >
<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
 <title>后台管理--机构列表</title>
 <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet" />
 <link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet" />
 <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
 <script src="${ctxStatic}/layui/layui.all.js"  type="text/javascript"></script>
 <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>
</head>
<body>
<div style="width:95%;margin:0 auto">
    <div id="list" class="list" lay-filter="list"></div>
 </div>
 
 <div style="width:80;text-align: right;margin-top:5px;margin-right:100px">
  <input type="button" class="button"  value="保存" id="btnsave" />
  <input type="button" class="button"  value="关闭" onclick="top.CloseOpenWindow()" />
 </div>
 
 
 
<input type="hidden" value="${roleid }" id="roleid"/>
 
 <script>
 layui.use(['form','table'], function(){
     var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
     var table = layui.table;
    
	 form.render();
	 
	 
	 
	 
	 table.render({
			elem : '#list'
			,height :310
			,url : 'get_menu_list' // 数据接口
			,page : true // 开启分页
			,limit : 30
			,id: 'menulist'
			,method:"post"
			,cols : [ [ // 表头
			            {type:'checkbox'}
			           ,{field : 'menuname',title : '菜单名称',width : 200,align : 'left'}
			           , {field : 'url',title : '菜单地址',width : 120,align : 'center'}
			           , {field : 'remark',title : '描述',width : 150,align : 'center'}
			           
		            ] ]
		    ,request:{
				type:'post'
			}
		    ,page: false
			,where:{roleid:$("#roleid").val()}
		    ,done: function(res, page, count){
		    	$("[data-field='menutype']").children().each(function(){  
                 if($(this).text()=='0'){  
                    $(this).text("菜单")  
                 }
                 else if($(this).text()=='1'){  
                     $(this).text("按钮")  
                  }
            }) 
            
            
            $("[data-field='menuname']").children().each(function(index){ 
         	   var dataarr=res.data;
         	   if(index==0){
		    			$(this).css({"text-align":"center"});
		    		}
		    		var thisdata=dataarr[index-1];
		    		if(thisdata){
		    			var text=$(this).text();
		                $(this).css({"text-indent":thisdata.level+"em"});
		    		}
           })  
		    	
		    }
		    
		});


	   
	 
	 
	 $("#btnsave").click(function(){
		 var checkStatus = table.checkStatus('menulist');
		 var data = checkStatus.data;
		 var length=data.length;
		 if(length==0){
			 alert('请选择资源');
			 return;
		 }
		 var menuids='';
		 for(i=0;i<length;i++){
			 menuids+=data[i].menuid+',';
		 }
	     var roleid=$("#roleid").val();
	     top.frames["iframe"].vRights.addrolemenu(roleid,menuids);
	 })
	 
 });  
 </script>
</body>
</html>